package base;

/**
 * @author 何昌杰
 */
public class Base15 {

    /**
     * 树的子结构
     * 输入两棵二叉树A和B，判断B是不是A的子结构。(约定空树不是任意一个树的子结构)
     *
     * B是A的子结构， 即 A中有出现和B相同的结构和节点值。
     *
     * 示例 1：
     *
     * 输入：A = [1,2,3], B = [3,1]
     * 输出：false
     * 示例 2：
     *
     * 输入：A = [3,4,5,1,2], B = [4,1]
     * 输出：true
     * 限制：
     *
     * 0 <= 节点个数 <= 10000
     *
     */
    public static void main(String[] args) {
        TreeNode A = new TreeNode(4);
        A.left = new TreeNode(2);
        A.left.left = new TreeNode(1);
        A.left.right = new TreeNode(3);
        A.right = new TreeNode(7);
        A.right.left = new TreeNode(6);
        A.right.right = new TreeNode(9);

        TreeNode B = mirrorTree(A);
        System.out.println();
    }


    public static TreeNode mirrorTree(TreeNode root) {
        if(root == null){return null;}
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
        mirrorTree(root.left);
        mirrorTree(root.right);
        return root;
    }

}
